﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class CardCenter_lianhuaOk : System.Web.UI.Page
{
    WebUtility util = new WebUtility();
    private BLL.PaymentBean payBean;//包装支付接口信息
    private BLL.GetPaymentAccount getAccount;//获取支付接口信息

    protected void Page_Load(object sender, EventArgs e)
    {
        //readonly field
        this.BillNo.ReadOnly = true;
        this.Amount.ReadOnly = true;
        this.MerCode.ReadOnly = true;

        string payId = "";
        //会话过期
        if (Session["totalMoney"] == null)
        {
            Response.Redirect("OnlinePurchaseCardStep1.aspx");
        }
        else if (Request.QueryString["payId"] == null || Request.QueryString["payId"] == "")
        {
            Response.Redirect("OnlinePurchaseCardStep1.aspx");
        }
        else {
            payId = Request.QueryString["payId"].ToString();
            getAccount = new BLL.GetPaymentAccount();
            //支付接口GUID标识
            payBean = getAccount.getPayInfo(payId);
            string payName = payBean.PaymentName;//支付接口名
            //参数：MerCode
            string merchantAccount = payBean.MerchantAccount;//商户账号
            string merchantPwd = payBean.MerchantPwd;//商户密码
            //参数：Amount
            string totalMoney = Session["totalMoney"].ToString();//支付金额
            //参数：PayType
            string payType = "01"; //全额支付
            string merUrl = payBean.MerUrl;//支付接口返回数据页面，即回调页面
            //参数：BillNo
            string billNo = WebUtility.GenrateSerialPayNumber();//15位订单编号
            //参数：SignMD5 [MD5(MerCode+BillNo+Amount+PayType+MerUrl+商户密码)]
            string md5Info = WebUtility.getMd5CryptedStr(merchantAccount + billNo + totalMoney + payType + merUrl + merchantPwd);

            ////检测支付信息
            if (!string.IsNullOrEmpty(merchantAccount) && !string.IsNullOrEmpty(merchantPwd) && !string.IsNullOrEmpty(totalMoney) &&
                !string.IsNullOrEmpty(merUrl) && !string.IsNullOrEmpty(billNo))
            {
                this.MerUrl.Value = merUrl;
                this.PayType.Value = payType;
                this.SignMD5.Value = md5Info;
                this.BillNo.Text = billNo;
                this.Amount.Text = totalMoney;
                this.MerCode.Text = merchantAccount;
            }
            else
            {
                util.AlertMsg("支付接口错误,请及时联系网站管理员!");
            }  
        }    

    }
}
